<template>
  <img alt="Vue logo" src="./assets/logo.png" />
  <p>姓名：{{ state.name }}</p>
  <p>年龄：{{ state.age }}</p>
  <button @click="updateState">改数据</button>
</template>

<script>
// 1. reactive是把普通对象转换成响应式数据
import { reactive } from "vue";
export default {
  name: "App",
  setup() {
    // 响应式数据
    const state = reactive({
      name: "jack",
      age: 18,
    });
    // 改数据
    const updateState = () => {
      state.name = "tom";
    };

    // 模板中需要使用的数据和函数：需要在setup中返回
    return { state, updateState };
  },
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
